package com.playball.lottery.frm.buyhall;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.JddMainActivity;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.ChildDTO;
import com.playball.lottery.customview.GroupDTO;
import com.playball.lottery.customview.JclqSFCgridviewAdapter;
import com.playball.lottery.customview.JczqGridview;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.kjinfo.KjinfoBasketBallResult;
import com.playball.lottery.frm.yhzx.BetRecordActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DateUtil;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.JCZQUtil;
import com.playball.lottery.util.LotConstants;


public class JcBasketballActivity extends BaseActivity implements DefConstants {

	private static final long serialVersionUID = 1L;

	private ArrayList<GroupDTO> groups;
	private List<ChildDTO> str_childs;

	/**
	 * 竞彩篮球的展开列表的适配器
	 */
	private static BastketBallAdapter jclist_adapter = null;

	/**
	 * 竞彩篮球混合投注适配器
	 */
	private static BasketBallHHTZAdapter jclq_hhtz_adapter = null;

	/**
	 * 竞彩篮球的展开列表
	 */
	private ExpandableListView jclist;
	private Map<String, Object> jcData;
	private List<Map<String, Object>> issueData;

	public String issueName; // 期号
	public String wkName;// 周几
	public String mCount;// 几场

	public String mId;// 赛事编号
	public String nMm;// 赛事类型
	public String BgColor;//赛事颜色
	public String eTime;// 截至时间
	public String hTeam;// 主队
	public String eQ = "";// 让球
	public String vTeam;// 让球
	public String sPRqspf;// 让球胜平负SP值
	public int isSingle;//是否单关
	/** 竞彩篮球胜分差主负SP值 */
	public String sPSFCF;
	/** 竞彩篮球胜分差主胜SP值 */
	public String sPSFCS;
	public boolean str_sbtn;// 零时胜
	public boolean str_fbtn;// 零时负
	public boolean str_pbtn;// 零时平

	private PopupWindow m_popupWindow;

	public ShowTipDialog showDialog = new ShowTipDialog();

	TextView btn_bottom_left, btn_bottom_right;

	TextView tv_selectNum;

	TextView bottom_tv_tips;

	Button buy_jcxh_Button01;

	/** 头部下拉选择框 */
	private Spinner sn_playMethod;
	/** 篮球玩法 */
	private String strLQWF = "RFSF";
	private String strLot = "让分胜负";
	/** 菜单弹出框 */
	private PopupWindow menu_popupWindow;
	/** 菜单弹出框 */
	private View menutypeview;
	private TextView top_title_tvplaytype;
	/** 判断是否从推送通知过来 */
	private Boolean ifPush;
	
	private View no_data;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.buy_jcxh_basket);
		tv_selectNum = (TextView) findViewById(R.id.bottom_tv_select_match);

		bottom_tv_tips = (TextView) findViewById(R.id.bottom_tv_tips);
		// 初始化表单
		initView();
		ifPush = getIntent().getBooleanExtra("ifPush", false);

		AsyncLoader task = new AsyncLoader();
		String[] parms = new String[2];
		parms[0] = "203";// 获取竞彩篮球场次数据
		JSONObject jsob = new JSONObject();
		parms[1] = jsob.toString();
		task.execute(parms);
		strLQWF = "RFSF";
		bottom_tv_tips.setText("请至少选择2场比赛");
		// 清空
		buy_jcxh_Button01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (TextUtils.equals(strLQWF, "HHTZ")) {
					if (jclq_hhtz_adapter.getSelNum() >= 1) {
						jclq_hhtz_adapter.clearSel();
						
			/*			MyDialog.Builder dialog = new MyDialog.Builder(JcBasketballActivity.this);
						dialog.setTitle("清空场次提示");
						dialog.setMessage("清空后您已选择的场次列表将会清空，确认继续?");
						dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
								jclq_hhtz_adapter.clearSel();
								dialog.cancel();
							}
						});
						dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.cancel();
							}
						}).create().show();*/
					} else {
						Toast.makeText(JcBasketballActivity.this, R.string.no_selection_session, Toast.LENGTH_SHORT)
								.show();
					}
				} else {
					if (ApplicationData.getInstance().getList_jcdto().size() >= 1) {
						clearData();
						/*MyDialog.Builder dialog = new MyDialog.Builder(JcBasketballActivity.this);
						dialog.setTitle("清空场次提示");
						dialog.setMessage("清空后您已选择的场次列表将会清空，确认继续?");
						dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
								clearData();
								dialog.cancel();
							}
						});
						dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
								dialog.cancel();
							}
						}).create().show();*/
					} else {
						Toast.makeText(JcBasketballActivity.this, R.string.no_selection_session, Toast.LENGTH_SHORT)
								.show();
					}
				}
			}
		});

		// 提交按钮
		btn_bottom_right.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				commit();
			}
		});
	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	private void commit() {
		if (checkUserLogin()) {
			if (TextUtils.equals(strLQWF, "HHTZ")) {
				List<ChildDTO> caculateData = new ArrayList<ChildDTO>();
				for (GroupDTO groupDTO : jclq_hhtz_adapter.getDatas()) {
					for (ChildDTO childDTO : groupDTO.children) {
						if (!TextUtils.isEmpty(childDTO.hhtz1) || !TextUtils.isEmpty(childDTO.hhtz2)
								|| !TextUtils.isEmpty(childDTO.hhtz3) || !TextUtils.isEmpty(childDTO.hhtz4)) {
							caculateData.add(childDTO);
						}
					}
				}
				int size = caculateData.size();
				if (size > 1) {
					if (size < 16) {
						Intent intent = new Intent();
						intent.putExtra("datas", jclq_hhtz_adapter.getDatas());
						intent.putExtra("IssueName", issueName);
						intent.setClass(JcBasketballActivity.this, JclqHhtzDetail.class);
						JcBasketballActivity.this.startActivityForResult(intent, 1);
					} else {
						Toast.makeText(JcBasketballActivity.this, R.string.select_fifteen_games_at_most,
								Toast.LENGTH_SHORT).show();
					}
				} else {
					Toast.makeText(JcBasketballActivity.this, R.string.select_at_least_two, Toast.LENGTH_SHORT).show();
				}
			} else if (!strLQWF.equals("SFC")) {
				if (!strLQWF.equals("SF")) {//不是胜负才执行
					if ((ApplicationData.getInstance().getList_jcdto().size()==1
							&& ApplicationData.getInstance().getList_jcdto().get(0).isSingle() ==1)||
							ApplicationData.getInstance().getList_jcdto().size() > 1) {
						if (ApplicationData.getInstance().getList_jcdto().size() < 16) {
							Intent intent = new Intent();
							intent.putExtra("list_jcdto", ApplicationData.getInstance().getList_jcdto());
							intent.putExtra("IssueName", issueName);
							intent.putExtra("strLQWF", strLQWF);
							intent.setClass(JcBasketballActivity.this, JcBasketballxhlbActivity.class);
							JcBasketballActivity.this.startActivityForResult(intent, REQ_CODE_JCBASKETBALL_TO_JCXHLB);// (intent);
						} else {
							Toast.makeText(JcBasketballActivity.this, R.string.select_fifteen_games_at_most,
									Toast.LENGTH_SHORT).show();
						}
					}else {
						Toast.makeText(JcBasketballActivity.this, R.string.select_at_least_two, Toast.LENGTH_SHORT).show();
					}
				} else {
					if (ApplicationData.getInstance().getList_jcdto().size() > 1){
						if (ApplicationData.getInstance().getList_jcdto().size() < 16) {
							Intent intent = new Intent();
							intent.putExtra("list_jcdto", ApplicationData.getInstance().getList_jcdto());
							intent.putExtra("IssueName", issueName);
							intent.putExtra("strLQWF", strLQWF);
							intent.setClass(JcBasketballActivity.this, JcBasketballxhlbActivity.class);
							JcBasketballActivity.this.startActivityForResult(intent, REQ_CODE_JCBASKETBALL_TO_JCXHLB);// (intent);
						} else {
							Toast.makeText(JcBasketballActivity.this, R.string.select_fifteen_games_at_most,
									Toast.LENGTH_SHORT).show();
						}
					}else {
						Toast.makeText(JcBasketballActivity.this, R.string.select_at_least_two, Toast.LENGTH_SHORT).show();
					}
				}
			} else {// 胜分差有单关，1 场
				if (ApplicationData.getInstance().getList_jcdto().size() > 0) {
					if (ApplicationData.getInstance().getList_jcdto().size() < 16) {
						Intent intent = new Intent();
						intent.putExtra("list_jcdto", ApplicationData.getInstance().getList_jcdto());
						intent.putExtra("IssueName", issueName);
						intent.putExtra("strLQWF", strLQWF);
						intent.setClass(JcBasketballActivity.this, JcBasketballxhlbActivity.class);
						JcBasketballActivity.this.startActivityForResult(intent, REQ_CODE_JCBASKETBALL_TO_JCXHLB);// (intent);
					} else {
						Toast.makeText(JcBasketballActivity.this, R.string.select_fifteen_games_at_most,
								Toast.LENGTH_SHORT).show();
					}
				} else {
					Toast.makeText(JcBasketballActivity.this, R.string.select_at_least_one, Toast.LENGTH_SHORT).show();
				}
			}
		} else {
			Intent intent = new Intent();
			intent.setClass(JcBasketballActivity.this, LoginActivity.class);
			startActivityForResult(intent, REQ_CODE_JCBASKETBALL_LOGIN);
		}
	}

	public static void clearHhtzSel() {
		if (jclq_hhtz_adapter != null)
			jclq_hhtz_adapter.clearSel();
	}

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		// 1.准备运行
		protected void onPreExecute() {
			showDialog.showDialog(JcBasketballActivity.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... params) {
			// 处理后台执行的任务，在后台线程执行
			String strResult;
			// 设置请求action
			String action = params[0];
			// 获取请求返回值
			strResult = GetRequestParams.getRequestResultKjInfo(params[1], action, getApplicationContext());
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			// //本地数据
			if (result != null) {
				// 获取接口数据
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						issueData = getCurrentlData(result);
						// 获取比赛场次信息赋值给groups
						getMatchInfo();
						if (groups!=null&&groups.size()>0) {
							jclist_adapter = new BastketBallAdapter(JcBasketballActivity.this, groups, strLQWF);
							jclist.setAdapter(jclist_adapter); // 绑定视图－适配器
							jclist.expandGroup(0);
							showDialog.closeDialog();
						}else{
							jclist.setVisibility(View.GONE);
							no_data.setVisibility(View.VISIBLE);
						}
						
					} else {
						Toast.makeText(JcBasketballActivity.this, js.getString("data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					showDialog.closeDialog();
				}
			} else {
				Toast.makeText(JcBasketballActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}
	}

	public String getWkByData(String data) {
		Calendar calendar = Calendar.getInstance();
		int year = Integer.parseInt(data.substring(0, 4));
		int month = Integer.parseInt(data.substring(4, 6));
		int day = Integer.parseInt(data.substring(6));
		calendar.set(year, month - 1, day);// 设置当前时间,月份是从0月开始计算
		int number = calendar.get(Calendar.DAY_OF_WEEK);// 星期表示1-7，是从星期日开始，
		String[] str = { "", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", };
		String myWeek = "1";
		switch (number) {
		case 1:
			myWeek = "7";
			break;
		case 2:
			myWeek = "1";
			break;
		case 3:
			myWeek = "2";
			break;
		case 4:
			myWeek = "3";
			break;
		case 5:
			myWeek = "4";
			break;
		case 6:
			myWeek = "5";
			break;
		case 7:
			myWeek = "6";
			break;
		default:
			break;
		}
		return myWeek;

	}

	// 配合接口得的方法
	// 获取比赛场次信息
	public void getMatchInfo() {
		groups = new ArrayList<GroupDTO>();
		if (issueData != null) {
			for (int i = 0; i < issueData.size(); i++) {
				mCount = issueData.get(i).get("MCount").toString();
				issueName = issueData.get(i).get("issue").toString();// 期号
				wkName = issueData.get(i).get("Wk").toString();// 周几
				tv_selectNum.setText(Html.fromHtml("已经选择" + "<font color=#a50000>" + 0 + "</font>" + "场比赛"));
				List<Map<String, Object>> matchData = ConvertJsonToList.getList(issueData.get(i).get("Matches")
						.toString());
				// 根据对应彩种处理数据//如果没有SP值，则不显示,删除此行数据//对比网站
				if (strLQWF.equals("RFSF")) {
					for (int j = 0; j < matchData.size(); j++) {
						if ("|".equals(matchData.get(j).get("SpRFSF").toString())) {
							matchData.remove(j);
							j--;// 这里防止有遗漏Item,正确做法让指针向前移动
						}
					}
				} else if (strLQWF.equals("SF")) {
					// 如果没有SP值，则不显示,删除此行数据
					for (int j = 0; j < matchData.size(); j++) {
						if ("|".equals(matchData.get(j).get("SpSF").toString())) {
							matchData.remove(j);
							j--;// 这里防止有遗漏Item,正确做法让指针向前移动
						}
					}
				} else if (strLQWF.equals("DXF")) {
					for (int j = 0; j < matchData.size(); j++) {
						if ("|".equals(matchData.get(j).get("SpDXF").toString())) {
							matchData.remove(j);
							j--;// 这里防止有遗漏Item,正确做法让指针向前移动
						}
					}
				} else if (strLQWF.equals("SFC")) {
					for (int j = 0; j < matchData.size(); j++) {
						if ("|||||||||||".equals(matchData.get(j).get("SpSFC").toString())) {
							matchData.remove(j);
							j--;// 这里防止有遗漏Item,正确做法让指针向前移动
						}
					}
				}
				// 重新对可投注比赛场数计算
				mCount = matchData.size() + "";
				List<ChildDTO> childs = new ArrayList<ChildDTO>();
				str_childs = new ArrayList<ChildDTO>();
				for (int j = 0; j < matchData.size(); j++) {
					mId = matchData.get(j).get("MID").toString();
					nMm = matchData.get(j).get("NMm").toString();// 赛事类型
					BgColor=matchData.get(j).get("BgColor").toString();// 赛事颜色
					eTime = matchData.get(j).get("ETime").toString();// 截至时间
					hTeam = matchData.get(j).get("HTeam").toString();// 主队
					vTeam = matchData.get(j).get("VTeam").toString();// 客队
					isSingle = Integer.parseInt(matchData.get(j).get("IsSingle_RFSF").toString());
					// 让分胜负asp值
					if (strLQWF.equals("RFSF")) {
						sPRqspf = matchData.get(j).get("SpRFSF").toString();// 让分胜负sp值
						eQ = sPRqspf.split("\\|")[0];
						// // 定义同样的数据格式
						sPRqspf = sPRqspf.substring(sPRqspf.indexOf("|") + 1);
					} else if (strLQWF.equals("SF")) {
						sPRqspf = matchData.get(j).get("SpSF").toString();// 胜负sp值
						// 此处SF没有数据，只是避免空指针。后面视图不显示
						eQ = sPRqspf.split("\\|")[0];
					} else if (strLQWF.equals("DXF")) {
						// 去掉第一个字段
						sPRqspf = matchData.get(j).get("SpDXF").toString();// 大小分sp值
						String[] arr = sPRqspf.split("\\|");
						eQ = arr[0];
						if (!eQ.equals("")) {
							if (eQ.startsWith("+") || eQ.startsWith("-")) {
								eQ = eQ.substring(1, eQ.length());
							}
						}
						// 定义同样的数据格式
						sPRqspf = sPRqspf.substring(sPRqspf.indexOf("|") + 1);
					}

					String spSFC = JCZQUtil.changeSFC2(matchData.get(j).get("SpSFC").toString());
					if (spSFC.split(",").length >= 1) {
						sPSFCS = spSFC.split(",")[0];// 胜分差主胜SP值
						sPSFCF = spSFC.split(",")[1];// 胜分差主负SP值
					}
					ChildDTO child = new ChildDTO();
					child.setmId(mId);
					child.setnMm(nMm);
					child.setBgColor(BgColor);
					child.seteTime(eTime);
					child.sethTeam(hTeam);
					child.seteQ(eQ);
					child.setvTeam(vTeam);
					child.setSingle(isSingle);
					if (TextUtils.equals(strLQWF, "HHTZ")) {
						if (matchData.get(j).get("SpSF") != null)
							child.setsPspf(matchData.get(j).get("SpSF").toString());
						if (matchData.get(j).get("SpRFSF") != null)
							child.setsPRqspf(matchData.get(j).get("SpRFSF").toString());
						if (matchData.get(j).get("SpDXF") != null)
							child.setsPdxf(matchData.get(j).get("SpDXF").toString());
						if (matchData.get(j).get("SpSFC") != null)
							child.setsPsfc(matchData.get(j).get("SpSFC").toString());
					} else {
						if (strLQWF.equals("SFC")) {
							// 胜分差主胜gridview是否显示
							child.setShowSFCS(false);
							child.setShowSFCF(false);
							// 存储胜分差SP值
							child.setsPsfcs(sPSFCS);
							child.setsPsfcf(sPSFCF);
							// 设置胜分差按钮选择状态为未选择
							child.setStr_sbtn(false);
							child.setStr_pbtn(false);
							// 胜分差主胜gridview按钮状态初始化
							List<String> list_sfcsgridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主胜6种赛果
								list_sfcsgridview_selectstate.add("false");
							}
							child.setList_sfcsgridview_selectstate(list_sfcsgridview_selectstate);
							// 胜分差主负gridview按钮状态初始化
							List<String> list_sfcfgridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主负6种赛果
								list_sfcfgridview_selectstate.add("false");
							}
							child.setList_sfcfgridview_selectstate(list_sfcfgridview_selectstate);
							// 设置按钮初始文字内容
							child.setBtnsfcscontent("主胜");
							child.setBtnsfcfcontent("客胜");
							// 胜分差sp值选择list初始化
							List<String> list_sfcsgridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主胜6种赛果SP
								list_sfcsgridview_selectsp.add("0");
							}
							child.setList_sfcsgridview_selectsp(list_sfcsgridview_selectsp);

							List<String> list_sfcfgridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主负6种赛果SP
								list_sfcfgridview_selectsp.add("0");
							}
							child.setList_sfcfgridview_selectsp(list_sfcfgridview_selectsp);
						} else {
							child.setsPRqspf(sPRqspf.replace("|", "-"));
						}

						child.setStr_sbtn(false);
						child.setStr_fbtn(false);
						child.setStr_pbtn(false);
					}
					childs.add(child);
					str_childs.add(child);
				}
				String temp = null;
				if (issueName.length() >= 8) {
					temp = issueName.substring(0, 4) + "-" + issueName.substring(4, 6) + "-"
							+ issueName.substring(6, issueName.length());
				} else {
					temp = issueName;
				}
				GroupDTO group = new GroupDTO(issueName, wkName + "  " + temp + "  共" + mCount + "场比赛可投注", childs);
				groups.add(group);
			}
		}
	}

	// 初始化
	public void initView() {
		jclist = (ExpandableListView) findViewById(R.id.jclist);
		//jclist.setVisibility(View.VISIBLE);
		no_data = findViewById(R.id.no_data);
		buy_jcxh_Button01 = (Button) findViewById(R.id.buy_ssqxh_Buttondel);
		// btn_bottom_left = (TextView) findViewById(R.id.bottom_left_btn);
		btn_bottom_right = (TextView) findViewById(R.id.bottom_right_btn);

		titleBar();

	}

	// 方法由ExpandableListView适配器来调用,转存至全局变量list来显示
	@SuppressWarnings("all")
	public void initMapData(ArrayList<ChildDTO> list_jcdto, String strLQWF) {
		if (!strLQWF.equals("SFC")) {
			if (ApplicationData.getInstance().getList_jcdto().size() != 0) {
				ApplicationData.getInstance().getList_jcdto().clear();
			}
			for (ChildDTO list_child : list_jcdto) {
				if (!list_child.str_sp.equals("")) {
					ApplicationData.getInstance().getList_jcdto().add(list_child);
				}
			}
		} else {
			// 比较APP和传过来的list,如果MID一样，需要删除旧的，添加新的;如果MID不一样，需要直接添加新的
			// 定义一个删除时零时的list
			List<ChildDTO> delList = new ArrayList();
			// // 判断第一次进来全局变量里有没有值.
			if (ApplicationData.getInstance().getList_jcdto().size() != 0) {
				for (ChildDTO app_child : ApplicationData.getInstance().getList_jcdto()) {
					for (ChildDTO list_child : list_jcdto) {
						String app_mid = "";
						String list_mid = "";
						if (app_child.getmId().equals(list_child.getmId())) {
							delList.add(app_child);
						}
					}
				}
				ApplicationData.getInstance().getList_jcdto().removeAll(delList);
			}
			for (ChildDTO list_child : list_jcdto) {
				// 全局变量存贮选择的赛事
				if (!((list_child.getBtnsfcscontent() + list_child.getBtnsfcfcontent()).equals("主胜客胜"))) {
					ApplicationData.getInstance().getList_jcdto().add(list_child);
				}
			}
		}

		tv_selectNum.setText("已经选择" + ApplicationData.getInstance().getList_jcdto().size() + "场比赛");
	}

	/**
	 * 获取当前期次信息
	 * 
	 * @param strResult
	 * @return
	 */
	private List<Map<String, Object>> getCurrentlData(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			list = ConvertJsonToList.getList(js.getString("Data").toString());
		} catch (JSONException e) {
			// 异常处理代码
			Log.e("error", e.toString());
		}
		return list;
	}

	/**
	 * 设置按钮显示文字为选择的赛事结果
	 * 
	 */
	public static void btnChildNamechange() {
		jclist_adapter.notifyDataSetChanged();
	}

	// TitleBar标题栏
	public void titleBar() {
		// Title信息(返回+Title)
		TextView tv_title_left = (TextView) findViewById(R.id.top_title_back);
		tv_title_left.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});
		top_title_tvplaytype = (TextView) findViewById(R.id.top_title_tvbd);
		top_title_tvplaytype.setText(strLot);
		top_title_tvplaytype.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(JcBasketballActivity.this);
				menutypeview = inflater.inflate(R.layout.jclq_menulink, null);
				menu_popupWindow = new PopupWindow(menutypeview, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
				menu_popupWindow.setBackgroundDrawable(new BitmapDrawable());

				menu_popupWindow.setFocusable(true);
				menu_popupWindow.setTouchable(true);
				menu_popupWindow.setOutsideTouchable(false);

				menu_popupWindow.showAtLocation(menutypeview, Gravity.CENTER | Gravity.TOP, 0, 0);
				menu_popupWindow.showAsDropDown(top_title_tvplaytype);
				menutypeview.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						// TODO Auto-generated method stub
						menu_popupWindow.dismiss();
					}
				});
				setBtnOnClickTopMenu(R.id.jclq_topmenulink_Button1);
				setBtnOnClickTopMenu(R.id.jclq_topmenulink_Button2);
				setBtnOnClickTopMenu(R.id.jclq_topmenulink_Button3);
				setBtnOnClickTopMenu(R.id.jclq_topmenulink_Button4);
				setBtnOnClickTopMenu(R.id.jclq_topmenulink_Button5);
				if (strLQWF.equals("RFSF")) {
					((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button1)).setSelected(true);
				} else if (strLQWF.equals("SF")) {
					((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button2)).setSelected(true);
				} else if (strLQWF.equals("SFC")) {
					((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button3)).setSelected(true);
				} else if (strLQWF.equals("DXF")) {
					((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button4)).setSelected(true);
				} else if (strLQWF.equals("HHTZ")) {
					((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button5)).setSelected(true);
				}

			}

		});

		final TextView btn_title_right = (TextView) findViewById(R.id.top_title_refres);
		btn_title_right.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(JcBasketballActivity.this);
				View menuview = inflater.inflate(R.layout.public_menulink02, null);

				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setOutsideTouchable(true);
				m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 0, 0);
				m_popupWindow.showAsDropDown(btn_title_right);

				menuview.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
					}
				});

				Button public_menulink_Button01 = (Button) menuview.findViewById(R.id.public_menulink_Button01);
				public_menulink_Button01.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							Intent intent0 = new Intent();
							intent0.putExtra("lotID", LotConstants.LOT_ID_JCLQ);
							intent0.setClass(JcBasketballActivity.this, BetRecordActivity.class);
							startActivity(intent0);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_JCBASKETBALL_LOGIN);
						}
					}
				});
				Button public_menulink_Button02 = (Button) menuview.findViewById(R.id.public_menulink_Button02);
				public_menulink_Button02.setVisibility(View.GONE);
				Button public_menulink_Button03 = (Button) menuview.findViewById(R.id.public_menulink_Button03);
				public_menulink_Button03.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO
						// Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						intent = new Intent(getApplicationContext(), KjinfoBasketBallResult.class);
						intent.putExtra("LotName", getString(R.string.kjinfo_match_lq_result));
						startActivity(intent);

					}
				});
				Button public_menulink_Button04 = (Button) menuview.findViewById(R.id.public_menulink_Button04);
				public_menulink_Button04.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO
						// Auto-generated method stub
						m_popupWindow.dismiss();
						// Intent intent = new Intent(
						// getApplicationContext(),
						// HelpActivity.class);
						// startActivity(intent);
						Intent intent = new Intent(getApplicationContext(), CaiPiaoHelp.class);
						intent.putExtra("cp_title", "竞彩篮球");
						intent.putExtra("cp_url", "jclq.html");
						startActivity(intent);
					}
				});
			}
		});
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		if (m_popupWindow != null) {
			m_popupWindow.dismiss();
		}
		return super.onTouchEvent(event);
	}

	public boolean checkUserLogin() {
		return true == ApplicationData.getInstance().isUserLogin();
	}

	/**
	 * 菜单玩法按钮事件
	 * 
	 * @param btnId
	 */
	protected void setBtnOnClickTopMenu(final int btnId) {
		Button btn = (Button) menutypeview.findViewById(btnId);
		btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					menu_popupWindow.dismiss();
					setOrderFieldMenu(btnId);
					// 发送不同彩种网络请求
					// reset();

				} catch (Exception e) {
					// TODO Auto-generated catch block
					// e.printStackTrace();
				}
			}
		});

	}

	/**
	 * 获取玩法及改变按钮背景
	 * 
	 * @param btnId
	 */
	protected void setOrderFieldMenu(int btnId) {
		// 恢复默认
		((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button1)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button2)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button3)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button4)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button5)).setSelected(false);

		switch (btnId) {
		case R.id.jclq_topmenulink_Button1:
			strLot = "让分胜负";
			strLQWF = "RFSF";
			bottom_tv_tips.setText("请至少选择2场比赛");
			((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button1)).setSelected(true);
			top_title_tvplaytype.setText(strLot);
			break;
		case R.id.jclq_topmenulink_Button2:
			strLot = "胜负";
			strLQWF = "SF";
			 bottom_tv_tips.setText("请至少选择2场比赛");
			((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button2)).setSelected(true);
			top_title_tvplaytype.setText(strLot);
			break;
		case R.id.jclq_topmenulink_Button3:
			strLot = "胜分差";
			strLQWF = "SFC";
	        bottom_tv_tips.setText("请至少选择1场比赛");
			((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button3)).setSelected(true);
			top_title_tvplaytype.setText(strLot);
			break;
		case R.id.jclq_topmenulink_Button4:
			strLot = "大小分";
			strLQWF = "DXF";
			  bottom_tv_tips.setText("请至少选择2场比赛");
			((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button4)).setSelected(true);
			top_title_tvplaytype.setText(strLot);
			break;
		case R.id.jclq_topmenulink_Button5:
			strLot = "混合过关";
			strLQWF = "HHTZ";
			 bottom_tv_tips.setText("请至少选择2场比赛");
			((Button) menutypeview.findViewById(R.id.jclq_topmenulink_Button5)).setSelected(true);
			top_title_tvplaytype.setText(strLot);
			break;
		}

		clearData();
		// 获取比赛场次信息赋值给groups
		getMatchInfo();

		// 构建ExpandableListView的适配器
		if (TextUtils.equals(strLQWF, "HHTZ")) {
			if (groups!=null&&groups.size()>0) {
				jclist.setVisibility(View.VISIBLE);
				jclq_hhtz_adapter = new BasketBallHHTZAdapter(JcBasketballActivity.this, groups);
				jclist.setAdapter(jclq_hhtz_adapter);
			}else{
				jclist.setVisibility(View.GONE);
				no_data.setVisibility(View.VISIBLE);
			}
			
		} else {
			if (groups!=null&&groups.size()>0) {
				jclist.setVisibility(View.VISIBLE);
				jclist_adapter = new BastketBallAdapter(JcBasketballActivity.this, groups, strLQWF);
				jclist.setAdapter(jclist_adapter); // 绑定视图－适配器
			}else{
				jclist.setVisibility(View.GONE);
				no_data.setVisibility(View.VISIBLE);
			}
			
		}

		jclist.expandGroup(0);
	}

	/**
	 * 清除用户选择的数据，恢复初始状态
	 */
	public void clearData() {
		if (groups != null) {
			// 清除数据
			for (int i = 0; i < groups.size(); i++) {
				if (groups.get(i).children.size() > 0) {
					// 若children不为空，循环设置children的checked
					for (ChildDTO child : groups.get(i).children) {
						if (!strLQWF.equals("SFC")) {
							child.str_sbtn = false;
							child.str_fbtn = false;
							child.str_pbtn = false;
							child.str_sp = "";
						} else {
							// 胜分差主胜gridview是否显示
							child.setShowSFCS(false);
							child.setShowSFCF(false);
							// 设置胜分差按钮选择状态为未选择
							child.setStr_sbtn(false);
							child.setStr_fbtn(false);
							// 胜分差主胜gridview按钮状态初始化
							List<String> list_sfcsgridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主胜6种赛果
								list_sfcsgridview_selectstate.add("false");
							}
							child.setList_sfcsgridview_selectstate(list_sfcsgridview_selectstate);
							// 胜分差主负gridview按钮状态初始化
							List<String> list_sfcfgridview_selectstate = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主负6种赛果
								list_sfcfgridview_selectstate.add("false");
							}
							child.setList_sfcfgridview_selectstate(list_sfcfgridview_selectstate);
							// 设置按钮初始文字内容
							child.setBtnsfcscontent("主胜");
							child.setBtnsfcfcontent("客胜");
							// 胜分差主胜gridview按钮选择内容初始化
							List<String> list_sfcsgridview_selectconcent = new ArrayList<String>();
							child.setList_sfcsgridview_selectconcent(list_sfcsgridview_selectconcent);
							// 胜分差主负gridview按钮选择内容初始化
							List<String> list_sfcfgridview_selectconcent = new ArrayList<String>();
							child.setList_sfcfgridview_selectconcent(list_sfcfgridview_selectconcent);
							child.setBtnsfcAllcontent("");
							// 胜分差sp值选择list初始化
							List<String> list_sfcsgridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主胜6种赛果SP
								list_sfcsgridview_selectsp.add("0");
							}
							child.setList_sfcsgridview_selectsp(list_sfcsgridview_selectsp);

							List<String> list_sfcfgridview_selectsp = new ArrayList<String>();
							for (int k = 0; k < 6; k++) {// 胜分差主负6种赛果SP
								list_sfcfgridview_selectsp.add("0");
							}
							child.setList_sfcfgridview_selectsp(list_sfcfgridview_selectsp);
							// 胜分差sp值选择初始化
							child.setBqc_selectsp("");
						}
					}
					ArrayList<ChildDTO> list_jcdto = new ArrayList<ChildDTO>();
					ApplicationData.getInstance().setList_jcdto(list_jcdto);
					if (TextUtils.equals(strLQWF, "HHTZ")) {
						if (jclq_hhtz_adapter != null)
							jclq_hhtz_adapter.notifyDataSetChanged();
					} else {
						jclist_adapter.notifyDataSetChanged();
					}
					tv_selectNum.setText("已经选择" + 0 + "场比赛");
				}
			}
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// 跳转至-开奖信息主页面
			if(ifPush){
				Intent intent = new Intent(this, JddMainActivity.class);
				startActivity(intent);
			}
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		
		if (requestCode == REQ_CODE_JCBASKETBALL_TO_JCXHLB &&  resultCode == RESULT_OK) {
			finish();
		}

		if (resultCode == RESULT_CANCELED) {
			if (requestCode == REQ_CODE_JCBASKETBALL_TO_JCXHLB) {
				clearData();
			}
		}
		
		if (requestCode == REQ_CODE_JCBASKETBALL_LOGIN) {
			if (resultCode == RESULT_OK) {
				commit();
			} else {

			}
		}

		if (requestCode == REQ_CODE_BUYMAIN && resultCode == RESULT_OK) {
			onKeyDown(KeyEvent.KEYCODE_BACK, null);
		}

		if (resultCode == 0) {
			// clearData();
		}
		if (resultCode == RESULT_OK) {
			if (requestCode == REQ_CODE_LQHHTZ) {
				jclq_hhtz_adapter.refreshWithData(data.getIntExtra("gindex", 0), data.getIntExtra("cindex", 0),
						(ChildDTO) data.getSerializableExtra("info"));
				;
			}
			if (requestCode == REQ_CODE_JCBASKETBALL) {

			} else if (requestCode == REQ_CODE_JCFOOT) {
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			} else {
				clearData();
			}
		}
		if (resultCode == 110) {
			onKeyDown(KeyEvent.KEYCODE_BACK, null);
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
	};

	/**
	 * 竞彩篮球数据适配器
	 * 
	 * @author Administrator
	 * 
	 */
	class BastketBallAdapter extends BaseExpandableListAdapter {

		/** 定义一个内部类，用于保存父View */
		private class GroupExpandableListHolder {
			TextView title;
			ImageView indicator;
		}

		/** 定义一个内部类，用于保存子View,让分胜负，胜负，大小分使用 */
		private class ChildExpandableListHolder {
			TextView tv_item_no_endtime, textView_matchname, tv_vTeam, tv_hTeam,tv_item_no_endtimes,tv_item_match_issingle;
			Button btn_rf;
			Button btn_zf;// 胜
			Button btn_zs;// 负
			View view_line;
		}

		/** 定义一个内部类，用于保存子View,胜分差使用 */
		class ChildExpandableListHolderSFC {
			TextView tv_item_no_endtime, textView_matchname, tv_vTeam, tv_hTeam,tv_item_no_endtimes,tv_item_match_issingle;
			Button btn_rf;
			Button btn_zf;
			Button btn_zs;

			LinearLayout llSFCSGridview;
			JczqGridview sFCSGridview;
			JclqSFCgridviewAdapter sFCSGridAdapter;

			LinearLayout llSFCFGridview;
			JczqGridview sFCFGridview;
			JclqSFCgridviewAdapter sFCFGridAdapter;
		}

		private Context context; // 父activity
		private LayoutInflater mChildInflater; // 用于加载listitem的布局xml
		private LayoutInflater mGroupInflater; // 用于加载group的布局xml
		private List<GroupDTO> groups; // 所有group
		private ArrayList<ChildDTO> list_children = new ArrayList<ChildDTO>();// 零时存储选择的赛事，由JcBasketballActivity来回调
		private String LQWF;

		public BastketBallAdapter(Context c, List<GroupDTO> groups) {
			context = c;
			mChildInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			mGroupInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			this.groups = groups;
		}

		public BastketBallAdapter(Context c, List<GroupDTO> groups, String strLQWF) {
			context = c;
			mChildInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			mGroupInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			this.groups = groups;
			LQWF = strLQWF;
		}

		/**
		 * 金山新接口方法
		 * 
		 * @param groupId
		 * @param dto
		 */
		public void addChildData(int groupId, ChildDTO dto) {
			groups.get(groupId).children.add(dto);
			notifyDataSetChanged();
		}

		@Override
		public Object getChild(int arg0, int arg1) {// 根据组索引和item索引，取得listitem
													// //
			return groups.get(arg0).children.get(arg1);
		}

		@Override
		public long getChildId(int arg0, int arg1) {// 返回item索引
			return arg1;
		}

		@Override
		public int getChildrenCount(int groupPosition) {// 根据组索引返回分组的子item数
			if (groups.size() <= 0)
				return 0;
			else
				return groups.get(groupPosition).children.size();
		}

		@Override
		public Object getGroup(int groupPosition) {// 根据组索引返回组
			return groups.get(groupPosition);
		}

		@Override
		public int getGroupCount() {// 返回分组数
			return groups.size();
		}

		@Override
		public long getGroupId(int groupPosition) {// 返回分组索引
			return groupPosition;
		}

		@Override
		public View getGroupView(int position, boolean isExpanded, View view, ViewGroup parent) {// 根据组索引渲染"组视图"
			GroupExpandableListHolder holder = null;
			if (view == null) {

				view = mGroupInflater.inflate(R.layout.item_group, null);
				holder = new GroupExpandableListHolder();
				holder.title = (TextView) view.findViewById(R.id.item_group_title);
				holder.indicator = (ImageView) view.findViewById(R.id.item_group_status);
				view.setTag(holder);
			} else {
				holder = (GroupExpandableListHolder) view.getTag();
			}
			GroupDTO info = this.groups.get(position);
			if (info != null) {
				holder.title.setText(DateUtil.getTName(info.title));
			}
			if (isExpanded) {
				holder.indicator.setImageResource(R.drawable.hemai_up);
			} else {
				holder.indicator.setImageResource(R.drawable.hemai_down);
			}
			// TODO Auto-generated method stub
			return view;
		}

		// 行渲染方法
		@Override
		public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView,
				ViewGroup parent) {
			if (!LQWF.equals("SFC")) {
				ChildExpandableListHolder holder = null; // 胜分差清空临时变量
				if (convertView == null) { // 若行未初始化
					// 通过flater初始化行视图
					convertView = mChildInflater.inflate(R.layout.jdd_jclq_rf_sf_dxf_item, null);
					// 并将行视图的5个子视图引用放到tag中
					holder = new ChildExpandableListHolder();
					holder.tv_item_no_endtimes = (TextView) convertView.findViewById(R.id.tv_item_no_endtimes);
					holder.tv_item_no_endtime = (TextView) convertView.findViewById(R.id.tv_item_no_endtime);
					holder.textView_matchname = (TextView) convertView.findViewById(R.id.tv_item_match_name);
					holder.tv_hTeam = (TextView) convertView.findViewById(R.id.tv_item_vteam);
					holder.tv_vTeam = (TextView) convertView.findViewById(R.id.tv_item_hteam);
					holder.btn_rf = (Button) convertView.findViewById(R.id.btn_item_rf);
					holder.view_line = convertView.findViewById(R.id.btn_item_rf_line);
					holder.btn_zf = (Button) convertView.findViewById(R.id.btn_item_s);
					holder.btn_zs = (Button) convertView.findViewById(R.id.btn_item_f);
					holder.tv_item_match_issingle= (TextView) convertView.findViewById(R.id.tv_item_match_issingle);
					convertView.setTag(holder);
				} else { // 若行已初始化，直接从tag属性获得子视图的引用
					holder = (ChildExpandableListHolder) convertView.getTag();
				}
				// 获得行数据（模型）
				final ChildDTO info = this.groups.get(groupPosition).children.get(childPosition);
				if (info != null) {
					String str_eq = "";
					String str_nmu = "";
					if (!LQWF.equals("SF")){
						holder.tv_item_match_issingle.setVisibility(info.isSingle()==1 ? View.VISIBLE:View.INVISIBLE);
					}else {
						holder.tv_item_match_issingle.setVisibility(View.INVISIBLE);
					}
					// 根据模型数据，设置行视图的控件值
					if (!info.eQ.equals("0")) {
						str_eq = "(" + info.eQ + ")";
					}
					if (info.nMm.length() < 4) {
						str_nmu = info.nMm;
					} else {
						str_nmu = info.nMm.substring(0, 4);
					}
					holder.tv_item_no_endtimes.setText((info.mId).substring(6) );// 130718301
					holder.tv_item_no_endtime.setText( DateUtil.getDateTime1(info.eTime));// 130718301
																										// 截取
																										// 301
					holder.textView_matchname.setText(str_nmu);
					if (info.BgColor==null||"".equals(info.BgColor)){
						holder.textView_matchname.setBackgroundColor(0xff000000);
					}else {
						holder.textView_matchname.setBackgroundColor(Color.parseColor(info.BgColor));
					}
					Spanned strBtn1 = null;
					Spanned strBtn3 = null;
					if (strLQWF.equals("RFSF")) {
						holder.btn_rf.setVisibility(View.VISIBLE);
						holder.view_line.setVisibility(View.GONE);
						holder.btn_rf.setText(Html.fromHtml("<font size='15dip' color='#000000'>"+  "VS" + "</font><br>"  + info.eQ ));
						holder.tv_hTeam.setText(info.hTeam);
						holder.tv_vTeam.setText(info.vTeam);
						if (info.sPRqspf.split("-").length >= 2) {
							strBtn1 = Html.fromHtml("<font size='15dip' color='#000000'>"+ info.vTeam  + "</font><br>"  + "主负" + info.sPRqspf.split("-")[0] );
							strBtn3 = Html.fromHtml("<font size='15dip' color='#000000'>"+ info.hTeam  + "</font><br>"  + "主胜" + info.sPRqspf.split("-")[1]);
						}
					} else if (strLQWF.equals("SF")) {
						holder.tv_hTeam.setText(info.hTeam);
						holder.tv_vTeam.setText(info.vTeam);
						if (info.sPRqspf.split("-").length >= 2) {
							strBtn1 = Html.fromHtml("<font size='15dip' color='#000000'>"+ info.vTeam  + "</font><br>"  + "主负" + info.sPRqspf.split("-")[0] );
							strBtn3 = Html.fromHtml("<font size='15dip' color='#000000'>"+ info.hTeam  + "</font><br>"  + "主胜" + info.sPRqspf.split("-")[1]);
					}
					} else if (strLQWF.equals("DXF")) {
						holder.btn_rf.setVisibility(View.VISIBLE);
						holder.view_line.setVisibility(View.GONE);
						holder.btn_rf.setText(Html.fromHtml("<font size='15dip' color='#000000'>"+  "VS" + "</font><br>"  + info.eQ ));
						holder.tv_hTeam.setText(info.hTeam);
						holder.tv_vTeam.setText(info.vTeam);
						if (info.sPRqspf.split("-").length >= 2) {
							strBtn1 = Html.fromHtml("<font size='15dip' color='#000000'>"+ info.vTeam  + "</font><br>"  + "大分" + info.sPRqspf.split("-")[0] );
							strBtn3 = Html.fromHtml("<font size='15dip' color='#000000'>"+ info.hTeam  + "</font><br>"  + "小分" + info.sPRqspf.split("-")[1]);

						}
					}
					if (strBtn1 != null) {
						holder.btn_zf.setText(strBtn1);
					}
					holder.btn_zf.setSelected(info.str_sbtn);
					holder.btn_zf.setTag(info);
					if (strBtn3 != null) {
						holder.btn_zs.setText(strBtn3);
					}
					holder.btn_zs.setSelected(info.str_fbtn);
					holder.btn_zs.setTag(info);

					holder.btn_zf.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View v) {
							Button button01 = (Button) v;
							ChildDTO child_info1 = (ChildDTO) v.getTag();
							// 当用户点击后，首先从零时List的取出指定mid的赛事，删除掉
							// 用来装需要删除的元素
							List delList = new ArrayList();
							for (ChildDTO child : list_children) {
								String jc_mid = child.getmId();
								if (child_info1.getmId() == jc_mid) {
									delList.add(child);
								}
							}
							list_children.removeAll(delList);
							// 判断赋新选中的值
							if (child_info1.str_sbtn) {
								child_info1.setStr_sp(child_info1.str_sp.replace("0," + info.sPRqspf.split("-")[0]
										+ "/", ""));
								child_info1.str_sbtn = false;
								button01.setSelected(child_info1.str_sbtn);
							} else {
								if (child_info1.str_sp == null) {
									child_info1.str_sp = "";
								}
								child_info1.setStr_sp(child_info1.str_sp + "0," + info.sPRqspf.split("-")[0] + "/");
								child_info1.str_sbtn = true;
								button01.setSelected(child_info1.str_sbtn);
							}
							list_children.add(child_info1);
							((JcBasketballActivity) context).initMapData(list_children, "RFSF");

						}
					});

					holder.btn_zs.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View v) {
							Button button03 = (Button) v;
							ChildDTO child_info3 = (ChildDTO) v.getTag();
							// 当用户点击后，首先从零时List的取出指定mid的赛事，删除掉
							// 用来装需要删除的元素
							List delList = new ArrayList();
							for (ChildDTO child : list_children) {
								String jc_mid = child.getmId();
								if (child_info3.getmId() == jc_mid) {
									delList.add(child);
								}
							}
							list_children.removeAll(delList);
							// 判断赋新的值
							if (child_info3.str_fbtn) {
								child_info3.setStr_sp(child_info3.str_sp.replace("3," + info.sPRqspf.split("-")[1]
										+ "/", ""));
								child_info3.str_fbtn = false;
								button03.setSelected(child_info3.str_fbtn);
							} else {
								if (child_info3.str_sp == null) {
									child_info3.str_sp = "";
								}
								child_info3.setStr_sp(child_info3.str_sp + "3," + info.sPRqspf.split("-")[1] + "/");
								child_info3.str_fbtn = true;
								button03.setSelected(child_info3.str_fbtn);
							}
							list_children.add(child_info3);
							// 回调initMapData这个方法，转存到全局变量里，选号结束
							((JcBasketballActivity) context).initMapData(list_children, "RfSF");

						}
					});
				}
			} else {
				ChildExpandableListHolderSFC holderSFC = null; // 胜分差清空临时变量
				if (convertView == null) { // 若行未初始化
					// 通过flater初始化行视图
					convertView = mChildInflater.inflate(R.layout.jdd_jclq_rf_sf_dxf_item, null);
					// 并将行视图的5个子视图引用放到tag中
					holderSFC = new ChildExpandableListHolderSFC();
					holderSFC.tv_item_no_endtimes = (TextView) convertView.findViewById(R.id.tv_item_no_endtimes);
					holderSFC.tv_item_no_endtime = (TextView) convertView.findViewById(R.id.tv_item_no_endtime);
					holderSFC.textView_matchname = (TextView) convertView.findViewById(R.id.tv_item_match_name);
					holderSFC.tv_hTeam = (TextView) convertView.findViewById(R.id.tv_item_vteam);
					holderSFC.tv_vTeam = (TextView) convertView.findViewById(R.id.tv_item_hteam);
					holderSFC.btn_zs = (Button) convertView.findViewById(R.id.btn_item_s);
					holderSFC.btn_zf = (Button) convertView.findViewById(R.id.btn_item_f);
					// 设置胜分差主胜gridview显示与否
					holderSFC.llSFCSGridview = (LinearLayout) convertView.findViewById(R.id.ll_myGridView_bfs);
					holderSFC.sFCSGridview = (JczqGridview) convertView.findViewById(R.id.myGridView_bfs);
					// 胜分差主负gridview
					holderSFC.llSFCFGridview = (LinearLayout) convertView.findViewById(R.id.ll_myGridView_bff);
					holderSFC.sFCFGridview = (JczqGridview) convertView.findViewById(R.id.myGridView_bff);
					convertView.setTag(holderSFC);
				} else { // 若行已初始化，直接从tag属性获得子视图的引用
					holderSFC = (ChildExpandableListHolderSFC) convertView.getTag();
				}
				// 获得行数据（模型）
				final ChildDTO info = this.groups.get(groupPosition).children.get(childPosition);
				if (info != null) {
					String str_nmu = "";
					// 根据模型数据，设置行视图的控件值
					if (info.nMm.length() < 4) {
						str_nmu = info.nMm;
					} else {
						str_nmu = info.nMm.substring(0, 4);
					}
					holderSFC.tv_item_no_endtimes.setText((info.mId).substring(6) );
					holderSFC.tv_item_no_endtime.setText( DateUtil.getDateTime1(info.eTime));
					holderSFC.textView_matchname.setText(str_nmu);
					if (info.BgColor==null||"".equals(info.BgColor)){
						holderSFC.textView_matchname.setBackgroundColor(0xff000000);
					}else {
						holderSFC.textView_matchname.setBackgroundColor(Color.parseColor(info.BgColor));
					}
					holderSFC.tv_hTeam.setText(info.hTeam);
					holderSFC.tv_vTeam.setText(info.vTeam);
					// 设置按钮文字为选择的内容
					if (info.getList_sfcsgridview_selectconcent().size() <= 1) {
						holderSFC.btn_zf.setText(Html.fromHtml("<font size='15dip' color='#000000'>"+ info.hTeam  + "</font><br>"  + info.btnsfcscontent));
					} else {
						holderSFC.btn_zf.setText("胜多个");
					}
					if (info.getList_sfcfgridview_selectconcent().size() <= 1) {
						holderSFC.btn_zs.setText(Html.fromHtml("<font size='15dip' color='#000000'>"+ info.vTeam  + "</font><br>"  + info.btnsfcfcontent));
					} else {
						holderSFC.btn_zs.setText("负多个");
					}

					holderSFC.btn_zf.setSelected(info.str_sbtn);
					holderSFC.btn_zf.setTag(info);

					holderSFC.btn_zs.setSelected(info.str_fbtn);
					holderSFC.btn_zs.setTag(info);

					holderSFC.btn_zf.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View v) {
							Button button01 = (Button) v;
							ChildDTO child_info1 = (ChildDTO) v.getTag();
							// 判断赋新选中的值
							if (child_info1.str_sbtn) {
								// gridview不显示
								child_info1.setShowSFCS(false);
								child_info1.str_sbtn = false;
								button01.setSelected(child_info1.str_sbtn);

							} else {
								child_info1.setShowSFCS(true);
								// 主胜，主负，只能同时显示一个gridview
								child_info1.setShowSFCF(false);
								child_info1.str_sbtn = true;
								// 主胜，主负按钮，只能同时显示一个按钮高亮
								child_info1.str_fbtn = false;

								button01.setSelected(child_info1.str_sbtn);

							}
							notifyDataSetChanged();
						}
					});

					holderSFC.btn_zs.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View v) {
							Button button02 = (Button) v;
							ChildDTO child_info2 = (ChildDTO) v.getTag();
							// 判断赋新的值
							if (child_info2.str_fbtn) {
								// gridview不显示
								child_info2.setShowSFCF(false);
								child_info2.str_fbtn = false;
								button02.setSelected(child_info2.str_fbtn);

							} else {
								// gridview显示
								child_info2.setShowSFCF(true);

								// 主胜，主负，只能同时显示一个gridview
								child_info2.setShowSFCS(false);

								child_info2.str_fbtn = true;
								// 主胜，主负按钮，只能同时显示一个按钮高亮
								child_info2.str_sbtn = false;

								button02.setSelected(child_info2.str_fbtn);

							}
							notifyDataSetChanged();
						}
					});

					// 设置胜分差主胜gridview显示与否
					if (info.isShowSFCS == false) {
						holderSFC.sFCSGridview.setVisibility(View.GONE);
					} else {
						holderSFC.sFCSGridview.setVisibility(View.VISIBLE);
					}
					// 按钮的文字
					String[] sfcs_titles = new String[] { "1-5", "6-10", "11-15", "16-20", "21-25", "26+" };
					String[] sfcs_nums;
					sfcs_nums = info.sPsfcs.split("\\|");
					holderSFC.sFCSGridAdapter = new JclqSFCgridviewAdapter(sfcs_titles, sfcs_nums, context, groups,
							groupPosition, childPosition, "sfcs");
					holderSFC.sFCSGridview.setAdapter(holderSFC.sFCSGridAdapter);// 设置菜单Adapter

					// 设置胜分差主负gridview显示与否
					if (info.isShowSFCF == false) {
						holderSFC.sFCFGridview.setVisibility(View.GONE);
					} else {
						holderSFC.sFCFGridview.setVisibility(View.VISIBLE);
					}
					// 按钮的文字
					String[] sfcf_titles = new String[] { "1-5", "6-10", "11-15", "16-20", "21-25", "26+" };
					String[] sfcf_nums;
					sfcf_nums = info.sPsfcf.split("\\|");
					holderSFC.sFCFGridAdapter = new JclqSFCgridviewAdapter(sfcf_titles, sfcf_nums, context, groups,
							groupPosition, childPosition, "sfcf");
					holderSFC.sFCFGridview.setAdapter(holderSFC.sFCFGridAdapter);// 设置菜单Adapter
				}

			}
			return convertView;
		}

		@Override
		public boolean hasStableIds() {// 行是否具有唯一id
			return false;
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {// 行是否可选
			return false;
		}
	}

	class BasketBallHHTZAdapter extends BaseExpandableListAdapter implements Serializable {

		/**
		 * 竞彩篮球数据混合过关适配器
		 */
		private static final long serialVersionUID = 1L;
		private Context context; // 父activity
		LayoutInflater inflater;
		private ArrayList<GroupDTO> datas;

		private Map<String, Integer> sel = new HashMap<String, Integer>();

		public BasketBallHHTZAdapter(Context c, ArrayList<GroupDTO> datas) {
			context = c;
			inflater = (LayoutInflater) c.getSystemService(LAYOUT_INFLATER_SERVICE);
			sel.clear();
			this.datas = datas;
		}

		public int getSelNum() {
			return (sel.isEmpty() ? 0 : sel.size());
		}

		public void clearSel() {
			for (GroupDTO gto : datas) {
				for (ChildDTO cto : gto.children) {
					cto.hhtz1 = "";
					cto.hhtz2 = "";
					cto.hhtz3 = "";
					cto.hhtz4 = "";
				}
			}
			sel.clear();
			this.notifyDataSetChanged();
		}

		public void refreshWithData(int gid, int cid, ChildDTO cDto) {
			datas.get(gid).children.remove(cid);
			datas.get(gid).children.add(cid, cDto);
			this.notifyDataSetChanged();

		}

		public ArrayList<GroupDTO> getDatas() {
			return datas;
		}

		@Override
		public Object getChild(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return datas.get(groupPosition).children.get(childPosition);
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return childPosition;
		}

		@Override
		public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
				View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ChildExpandableListHolder holder = null; // 清空临时变量
			if (convertView == null) { // 若行未初始化
				// 通过flater初始化行视图
				convertView = inflater.inflate(R.layout.jdd_jclq_rf_sf_dxf_items, null);
				// 并将行视图的5个子视图引用放到tag中
				holder = new ChildExpandableListHolder();
				holder.tv_item_no_endtimes = (TextView) convertView.findViewById(R.id.tv_item_no_endtimes);
				holder.tv_item_no_endtime = (TextView) convertView.findViewById(R.id.tv_item_no_endtime);
				holder.textView_matchname = (TextView) convertView.findViewById(R.id.tv_item_match_name);
				holder.tv_hTeam = (TextView) convertView.findViewById(R.id.tv_item_vteam);
				holder.tv_vTeam = (TextView) convertView.findViewById(R.id.tv_item_hteam);
				holder.btn_rf = (Button) convertView.findViewById(R.id.btn_item_rf);
				holder.view_line_rf = convertView.findViewById(R.id.btn_item_rf_line);
				holder.view_line_zs = convertView.findViewById(R.id.btn_item_rf_line_zs);
				holder.btn_zf = (Button) convertView.findViewById(R.id.btn_item_s);
				holder.btn_zs = (Button) convertView.findViewById(R.id.btn_item_f);
				convertView.setTag(holder);
			} else { // 若行已初始化，直接从tag属性获得子视图的引用
				holder = (ChildExpandableListHolder) convertView.getTag();
			}

			final GroupDTO info1 = this.datas.get(groupPosition);
			// 获得行数据（模型）
			final String wkn = DateUtil.getTName(info1.title);
			final ChildDTO info = this.datas.get(groupPosition).children.get(childPosition);
			if (info != null) {
				String str_nmu = "";
				// 根据模型数据，设置行视图的控件值
				if (info.nMm.length() < 4) {
					str_nmu = info.nMm;
				} else {
					str_nmu = info.nMm.substring(0, 4);
				}
				holder.tv_item_no_endtimes.setText((info.mId).substring(6) );// 130718301
				holder.tv_item_no_endtime.setText(DateUtil.getDateTime1(info.eTime));// 130718301
				holder.tv_hTeam.setText(info.hTeam);
				holder.tv_vTeam.setText(info.vTeam);
				holder.textView_matchname.setText(str_nmu);
				if (info.BgColor==null||"".equals(info.BgColor)){
					holder.textView_matchname.setBackgroundColor(0xff000000);
				}else {
					holder.textView_matchname.setBackgroundColor(Color.parseColor(info.BgColor));
				}
				holder.btn_zs.setVisibility(View.GONE);
				holder.view_line_zs.setVisibility(View.GONE);
				String btnName = "";
				if (!TextUtils.isEmpty(info.hhtz1)) {
					if (info.hhtz1.length() >= 1) {
						btnName += " 胜负:";
						if (info.hhtz1.contains("1")) {
							btnName += " 主胜";
						}
						if (info.hhtz1.contains("2")) {
							btnName += " 主负";
						}
					}
				}
				if (!TextUtils.isEmpty(info.hhtz2)) {
					if (info.hhtz2.length() >= 1) {
						btnName += " 让分胜负:";
						if (info.hhtz2.contains("1")) {
							btnName += " 主胜";
						}
						if (info.hhtz2.contains("2")) {
							btnName += " 主负";
						}
					}
				}
				if (!TextUtils.isEmpty(info.hhtz3)) {
					if (info.hhtz3.length() >= 1) {
						btnName += " 大小分:";
						if (info.hhtz3.contains("1")) {
							btnName += " 大分";
						}
						if (info.hhtz3.contains("2")) {
							btnName += " 小分";
						}
					}
				}
				if (!TextUtils.isEmpty(info.hhtz4)) {
					if (info.hhtz4.length() >= 1) {
						btnName += " 胜分差:";
						String tem = "";
						if (info.hhtz4.contains("1")) {
							tem += " 1-5";
						}
						if (info.hhtz4.contains("2")) {
							tem += " 6-10";
						}
						if (info.hhtz4.contains("3")) {
							tem += " 11-15";
						}
						if (info.hhtz4.contains("4")) {
							tem += " 16-20";
						}
						if (info.hhtz4.contains("5")) {
							tem += " 21-25";
						}
						if (info.hhtz4.contains("6")) {
							tem += " 客胜其他";
						}
						if (tem.length() >= 3) {
							btnName += ("客胜" + tem);
						}
						tem = "";
						if (info.hhtz4.contains("a")) {
							tem += " 1-5";
						}
						if (info.hhtz4.contains("b")) {
							tem += " 6-10";
						}
						if (info.hhtz4.contains("c")) {
							tem += " 11-15";
						}
						if (info.hhtz4.contains("d")) {
							tem += " 16-20";
						}
						if (info.hhtz4.contains("e")) {
							tem += " 21-25";
						}
						if (info.hhtz4.contains("f")) {
							tem += " 主胜其他";
						}
						if (tem.length() >= 3) {
							btnName += ("主胜" + tem);
						}
					}
				}
				String key = groupPosition + "" + childPosition;
				if (btnName.length() >= 2) {
					holder.btn_zf.setText(btnName.length() > 16 ? btnName.substring(0, 16) + "..." : btnName);
					holder.btn_zf.setSelected(true);

					if (sel.containsKey(key) == false) {
						sel.put(key, 1);
					}
				} else {
					holder.btn_zf.setText("选择赛事方案");
					holder.btn_zf.setSelected(false);
					if (sel.containsKey(key) == true) {
						sel.remove(key);
					}
				}
				tv_selectNum.setText("已经选择" + jclq_hhtz_adapter.getSelNum() + "场比赛");
				holder.btn_zf.setTag(info);
				holder.btn_zf.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(JcBasketballActivity.this, JclqHhtz.class);
						intent.putExtra("info", info);
						intent.putExtra("wk", wkn);
						intent.putExtra("gindex", groupPosition);
						intent.putExtra("cindex", childPosition);
						startActivityForResult(intent, REQ_CODE_LQHHTZ);
					}
				});
			}
			return convertView;

		}

		@Override
		public int getChildrenCount(int groupPosition) {
			// TODO Auto-generated method stub
			if (datas.size() <= 0) {
				return 0;
			}
			return datas.get(groupPosition).children.size();
		}

		@Override
		public Object getGroup(int groupPosition) {
			// TODO Auto-generated method stub
			return datas.get(groupPosition);
		}

		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			return datas.size();
		}

		@Override
		public long getGroupId(int groupPosition) {
			// TODO Auto-generated method stub
			return groupPosition;
		}

		@Override
		public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			GroupExpandableListHolder holder = null;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_group, null);
				holder = new GroupExpandableListHolder();
				holder.title = (TextView) convertView.findViewById(R.id.item_group_title);
				holder.indicator = (ImageView) convertView.findViewById(R.id.item_group_status);
				convertView.setTag(holder);
			} else {
				holder = (GroupExpandableListHolder) convertView.getTag();
			}
			// 未完成
			GroupDTO info = this.datas.get(groupPosition);
			if (info != null) {
				// 根据模型值设置textview的文本
				holder.title.setText(DateUtil.getTName(info.title));
			}
			if (true == isExpanded) {
				holder.indicator.setImageResource(R.drawable.hemai_up);
			} else {
				holder.indicator.setImageResource(R.drawable.hemai_down);
			}
			return convertView;
		}

		@Override
		public boolean hasStableIds() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return false;
		}

		// 定义一个内部类，用于保存父View
		private class GroupExpandableListHolder {
			TextView title;
			ImageView indicator;
		}

		private class ChildExpandableListHolder {
			TextView tv_item_no_endtime, textView_matchname, tv_vTeam, tv_hTeam,tv_item_no_endtimes;
			Button btn_rf;
			Button btn_zf;// 胜
			Button btn_zs;// 负
			View view_line_rf;
			View view_line_zs;
		}
	}
}